package ar.com.ctrln.view.dashboard.ventas.servicio;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventQueue;
import org.zkoss.zk.ui.event.EventQueues;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zul.Button;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Window;

import ar.com.ctrln.control.mantenimiento.ticket.RegistrarTicket;
import ar.com.ctrln.control.ventas.servicio.RegistrarContratacionServicio;
import ar.com.ctrln.persistence.model.cliente.Cliente;
import ar.com.ctrln.persistence.model.servicios.telefonia.Operador;
import ar.com.ctrln.view.render.mantenimiento.ticket.SelectClienteRowRender;
import ar.com.ctrln.view.ui.comportamientoVentana.AbstractMinimizarVentana;

@SuppressWarnings("unused")
@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class SeleccionarOperadorController extends AbstractMinimizarVentana {

	private static final long serialVersionUID = -6047378427213826430L;

	@WireVariable
	private RegistrarTicket registrarTicket;

	@WireVariable
	private RegistrarContratacionServicio registrarContratacion;

	private Cliente emisor;

	private Operador operador;

	@Wire
	private Window wAgregarOperador;

	@Wire
	private Listbox lbOperadores;

	@Wire
	private Button btnSeleccionarOperador;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		System.out.println(registrarContratacion.listaOperadores());
		lbOperadores.setModel(new ListModelList<Operador>(registrarContratacion
				.listaOperadores()));

	}

	@Listen("onClick = #btnSeleccionarOperador")
	public void traerSeleccionOperador() {
		if (lbOperadores.getSelectedItem() != null) {
			operador = lbOperadores.getSelectedItem().getValue();
			this.wAgregarOperador.onClose();
			EventQueue<Event> eq = EventQueues.lookup("seleccionar_operador",
					EventQueues.DESKTOP, false);
			eq.publish(new Event("onButtonClick", btnSeleccionarOperador,
					operador));
		}
	}

	@Listen("onCreate = #lbClientes")
	public void listarClientes() {

	}

}
